package com.poster.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class RedisUtils {


    private final StringRedisTemplate redisTemplate;


    public RedisUtils(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
    

    /**
     * 删除键
     * @param key 键
     */
    public void del(String key){
        if (!exists(key)) {
            log.warn("删除redis key: {} 失败，因为key不存在", key);
            return;
        }
        redisTemplate.delete(key);
    }

    /**
     *判断redis key是否存在
     * @param key 键
     * @return 是否存在
     */
    public boolean exists(String key) {
        return redisTemplate.hasKey(key);
    }
}
